/**
 * AnalyzerDemo.java	1.0 2007 六月 13 17:11:07,创建
 */


package lia.ch4;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.Analyzer;

/**
 *
 * @author 杨帆
 * @version 1.0 2007 六月 13 17:11:07,创建
 */
public class AnalyzerDemo
{
	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(AnalyzerDemo.class);

	private String[] strings;
	private Analyzer[] analyzers;

	public AnalyzerDemo()
	{
		this.strings = new String[0];
		this.analyzers = new Analyzer[0];
	}

	public void execute() throws IOException
	{
		for(String text : strings)
		{
			analyze(text);
		}
	}

	private void analyze(String text) throws IOException
	{
		log.debug("Analyzing \"" + text + "\"");
		for(Analyzer analyzer : this.analyzers)
		{
			String name = analyzer.getClass().getName();
			name = name.substring(name.lastIndexOf(".") + 1);
			log.debug("\t" + name + ":");
			AnalyzerUtils.displayTokens(analyzer, text);
		}
	}

	public void setAnalyzers(Analyzer... analyzers)
	{
		this.analyzers = analyzers;
	}

	public void setStrings(String... strings)
	{
		this.strings = strings;
	}
}
